package com.aaa.service.sds.impl;


import cn.hutool.core.util.ObjectUtil;
import com.aaa.aspect.InsertAnn;
import com.aaa.aspect.UpdateAnn;
import com.aaa.dao.sds.QuestionSdsDao;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.sds.QuestionSds;
import com.aaa.service.sds.QuestionSdsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 问题表(QuestionSds)表服务实现类
 *
 * @author makejava
 * @since 2022-08-29 20:40:06
 */
@Service
public class QuestionSdsServiceImpl implements QuestionSdsService {
    @Autowired
    QuestionSdsDao questionSdsDao;

    //查询所有
    @Override
    public Page queryAll(PageSortEntity page, QuestionSds questionSds) {
        PageHelper.startPage(page.getPage(), page.getLimit(), page.getOrderString());
        List<QuestionSds> list = questionSdsDao.queryAll(questionSds);
        Page page1 = (Page) list;
        return page1;
    }

    //添加
    @InsertAnn
    @Override
    public boolean insert(QuestionSds questionSds) {
        return questionSdsDao.insert(questionSds);
    }

    //删除
    @Override
    public boolean delete(String id) {
        return questionSdsDao.delete(id);
    }

    //修改
    @UpdateAnn
    @Override
    public boolean update(QuestionSds questionSds) {
        return questionSdsDao.update(questionSds);
    }

    //名字唯一性校验
    @Override
    public boolean repetitionName(QuestionSds questionSds) {
        QuestionSds pp = questionSdsDao.repetitionName(questionSds);
        if (ObjectUtil.isEmpty(pp) || pp.getId().equals(questionSds.getId())) {
            return true;
        } else {
            return false;
        }
    }

    //ID唯一性校验
    @Override
    public boolean repetitionID(QuestionSds qSd) {
        QuestionSds questionSds = questionSdsDao.repetitionID(qSd);
        if (ObjectUtil.isNotEmpty(questionSds)){
            return false;
        }
        return true;
    }

}
